<?php

if (!isset($_GET['img'])) exit();

// GET INFORMATIONS
$path = $_GET['img'];
$name = basename($path);
$info = pathinfo($path);
$medias = array(
	"gif" => "image/gif",
	"jpeg" => "image/jpg",
	"jpg" => "image/jpg",
	"png" => "image/png"
	);
if(!isset($medias[strtolower($info["extension"])])) exit();
$type = $medias[strtolower($info["extension"])];
$size = filesize($path);

// SEND HEADERS
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: $type");
header("Content-Disposition: attachment; filename=\"$name\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: $size");

// OUTPUT FILE CONTENT
$fh = fopen($path, "rb");
$buffer = fread($fh, $size);
fclose($fh);
print $buffer;
exit();

?>